home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 8: LINUX Games / Linux Cubed Series 8 - LINUX Games.iso / games / muds / mordor_2.000 / mordor_2 / src / post.c < prev    next >
C/C++ Source or Header  |  1994-06-25  |  6KB  |  269 lines

  1. /*
  2.  * POST.C:
  3.  *
  4.  *    These routines are for the game post office.
  5.  *
  6.  *    Copyright (C) 1991, 1992, 1993 Brett J. Vickers
  7.  *
  8.  */
  9.  
  10. #include "mstruct.h"
  11. #include "mextern.h"
  12.  
  13. /************************************************************************/
  14. /*                postsend                */
  15. /************************************************************************/
  16.  
  17. /* This function allows a player to send a letter to another player if    */
  18. /* he/she is in a post office.                        */
  19.  
  20. int postsend(ply_ptr, cmnd)
  21. creature    *ply_ptr;
  22. cmd        *cmnd;
  23. {
  24.     room    *rom_ptr;
  25.     char    file[80];
  26.     int    fd, ff;
  27.  
  28.     fd = ply_ptr->fd;
  29.     rom_ptr = ply_ptr->parent_rom;
  30.  
  31.     if(!F_ISSET(rom_ptr, RPOSTO)) {
  32.         print(fd, "This is not a post office.\n");
  33.         return(0);
  34.     }
  35.  
  36.     if(cmnd->num < 2) {
  37.         print(fd, "Mail whom?\n");
  38.         return(0);
  39.     }
  40.  
  41.     cmnd->str[1][0] = up(cmnd->str[1][0]);
  42.     sprintf(file, "%s/%s", PLAYERPATH, cmnd->str[1]);
  43.     ff = open(file, O_RDONLY, 0);
  44.  
  45.     if(ff < 0) {
  46.         print(fd, "That player does not exist.\n");
  47.         return(0);
  48.     }
  49.  
  50.     close(ff);
  51.  
  52.     print(fd, "Enter your message now. Use an empty line to finish.\nEach line should be NO LONGER THAN 80 CHARACTERS.\n-: ");
  53.  
  54.     sprintf(Ply[fd].extr->tempstr[0], "%s/%s", POSTPATH, cmnd->str[1]);
  55.  
  56.     F_SET(Ply[fd].ply, PREADI);
  57.     output_buf();
  58.     Ply[fd].io->intrpt &= ~1;
  59.     Ply[fd].io->fn = postedit;
  60.     Ply[fd].io->fnparam = 1;
  61.     return(DOPROMPT);
  62.  
  63. }
  64.  
  65. /************************************************************************/
  66. /*                postedit                */
  67. /************************************************************************/
  68.  
  69. /* This function is called when a player is editing a message to send    */
  70. /* to another player.  Its major flaw is that it sends the line just    */
  71. /* typed to the target's mail file immediately.  So if two people were    */
  72. /* simultaneously mailing the same person, it could get messy.        */
  73.  
  74. void postedit(fd, param, str)
  75. int    fd;
  76. int    param;
  77. char    *str;
  78. {
  79.     char    outstr[85], datestr[40];
  80.     long    t;
  81.     int    ff;
  82.  
  83.     if(!str[0]) {
  84.         F_CLR(Ply[fd].ply, PREADI);
  85.         print(fd, "Mail sent.\n");
  86.         RETURN(fd, command, 1);
  87.     }
  88.  
  89.     ff = open(Ply[fd].extr->tempstr[0], O_CREAT | O_APPEND | O_RDWR, ACC);
  90.     if(ff < 0)
  91.         merror("postedit", FATAL);
  92.  
  93.     if(param == 1) {
  94.         time(&t);
  95.         strcpy(datestr, (char *)ctime(&t));
  96.         datestr[strlen(datestr)-1] = 0;
  97.         sprintf(outstr, "\n---\nMail from %s (%s):\n\n",
  98.             Ply[fd].ply->name, datestr);
  99.         write(ff, outstr, strlen(outstr));
  100.     }
  101.  
  102.     strncpy(outstr, str, 79);
  103.     outstr[79] = 0;
  104.     strcat(outstr, "\n");
  105.  
  106.     write(ff, outstr, strlen(outstr));
  107.  
  108.     close(ff);
  109.  
  110.     print(fd, "-: ");
  111.  
  112.     output_buf();
  113.     Ply[fd].io->intrpt &= ~1;
  114.     RETURN(fd, postedit, 2);
  115. }
  116.  
  117. /************************************************************************/
  118. /*                postread                */
  119. /************************************************************************/
  120.  
  121. /* This function allows a player to read his or her mail.        */
  122.  
  123. int postread(ply_ptr, cmnd)
  124. creature    *ply_ptr;
  125. cmd        *cmnd;
  126. {
  127.     room    *rom_ptr;
  128.     char     file[80];
  129.     int    fd;
  130.     
  131.     fd = ply_ptr->fd;
  132.     rom_ptr = ply_ptr->parent_rom;
  133.  
  134.     if(!F_ISSET(rom_ptr, RPOSTO)) {
  135.         print(fd, "This is not a post office.\n");
  136.         return(0);
  137.     }
  138.  
  139.     strcpy(file, POSTPATH);
  140.  
  141.     strcat(file, "/");
  142.     strcat(file, ply_ptr->name);
  143.     view_file(fd, 1, file);
  144.     return(DOPROMPT);
  145.  
  146. }
  147.  
  148. /************************************************************************/
  149. /*                postdelete                */
  150. /************************************************************************/
  151.  
  152. /* This function allows a player to delete his or her mail.        */
  153.  
  154. int postdelete(ply_ptr, cmnd)
  155. creature    *ply_ptr;
  156. cmd        *cmnd;
  157. {
  158.     room    *rom_ptr;
  159.     char    file[80];
  160.     int    fd;
  161.  
  162.     fd = ply_ptr->fd;
  163.     rom_ptr = ply_ptr->parent_rom;
  164.  
  165.     if(!F_ISSET(rom_ptr, RPOSTO)) {
  166.         print(fd, "This is not a post office.\n");
  167.         return(0);
  168.     }
  169.  
  170.     sprintf(file, "%s/%s", POSTPATH, ply_ptr->name);
  171.  
  172.     print(fd, "Mail deleted.\n");
  173.  
  174.     unlink(file);
  175.  
  176.     return(0);
  177. }
  178. /************************************************************************/
  179. /*                              notepad                                 */
  180. /************************************************************************/
  181. int notepad(ply_ptr, cmnd)
  182. creature    *ply_ptr;
  183. cmd     *cmnd;
  184. {
  185.     room    *rom_ptr;
  186.     char    file[80];
  187.     int fd, ff;
  188.  
  189.     fd = ply_ptr->fd;
  190.     rom_ptr = ply_ptr->parent_rom;
  191.  
  192.     if (ply_ptr->class < CARETAKER)
  193.         return(PROMPT);
  194.  
  195.     sprintf(file, "%s/DM_pad", POSTPATH);
  196.  
  197.     if (cmnd->num == 2) {
  198.         if( low(cmnd->str[1][0]) == 'a'){
  199.             strcpy(Ply[fd].extr->tempstr[0],file);
  200.             print(fd, "DM notepad:\n->");
  201.             F_SET(Ply[fd].ply, PREADI);
  202.             output_buf();
  203.             Ply[fd].io->intrpt &= ~1;
  204.             Ply[fd].io->fn = noteedit;
  205.             Ply[fd].io->fnparam = 1;
  206.             return(DOPROMPT);
  207.         }
  208.         else if (low(cmnd->str[1][0]) == 'd'){
  209.             unlink(file);
  210.             print(fd,"Clearing DM notepad\n");
  211.             return(PROMPT);
  212.         }
  213.         else{
  214.             print(fd,"invalid option.\n");
  215.             return(PROMPT);
  216.         }
  217.     }
  218.     else{
  219.         view_file(fd, 1, file);
  220.         return(DOPROMPT);
  221.     }
  222. }
  223.  
  224. /************************************************************************/
  225. /*                              noteedit                                */
  226. /************************************************************************/
  227.  
  228. void noteedit(fd, param, str)
  229. int fd;
  230. int param;
  231. char    *str;
  232. {
  233.     char    outstr[85], tmpstr[40];
  234.     long    t;
  235.     int ff;
  236.  
  237.     if(str[0] == '.') {
  238.         F_CLR(Ply[fd].ply, PREADI);
  239.         print(fd, "Message appended.\n");
  240.         RETURN(fd, command, 1); 
  241.     }
  242.  
  243.     ff = open(Ply[fd].extr->tempstr[0], O_RDONLY, 0);
  244.     if(ff < 0){
  245.         ff = open(Ply[fd].extr->tempstr[0], O_CREAT | O_RDWR, ACC);
  246.         sprintf(tmpstr,"            %s\n\n","=== DM Notepad ===");
  247.         write(ff, tmpstr,strlen(tmpstr));
  248.     }
  249.     close(ff);
  250.  
  251.     ff = open(Ply[fd].extr->tempstr[0], O_CREAT | O_APPEND | O_RDWR, ACC);
  252.     if(ff < 0)
  253.         merror("noteedit", FATAL);
  254.  
  255.     strncpy(outstr, str, 79);
  256.     outstr[79] = 0;
  257.     strcat(outstr, "\n");
  258.  
  259.     write(ff, outstr, strlen(outstr));
  260.  
  261.     close(ff);
  262.  
  263.     print(fd, "->");
  264.  
  265.     output_buf();
  266.     Ply[fd].io->intrpt &= ~1;
  267.     RETURN(fd, noteedit, 2);
  268. }
  269.